﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace WqLunTan.Extensions
{
    public static class DateTimeExtensions
    {

        /// <summary>
        /// UTC时间, Unix时间戳的起始时间
        /// </summary>
        public static DateTimeOffset UnixStartTime = new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero);

        /// <summary>
        /// 获取Unix时间戳
        /// </summary>
        /// <param name="dateTime"></param>
        /// <returns></returns>
        public static long ToUnixLong(this DateTimeOffset dateTime)
        {
            var utcNow = dateTime.ToUniversalTime();
            return (utcNow - UnixStartTime).Ticks;
        }
    }
}
